from marshmallow import fields
from marshmallow_sqlalchemy import SQLAlchemySchema
from api.database import db
from api.apps.books.models import Book


class BookSchema(SQLAlchemySchema):
    class Meta(SQLAlchemySchema.Meta):
        model = Book
        sqlalchemy_session = db.session
        load_instance = True

    id = fields.Integer(dump_only=True)
    title = fields.String(required=True)
    year = fields.Integer(required=True)
    author_id = fields.Integer(required=True)
